<template>
  <div>
    <el-table :data="GoodsList" style="width: 100%" max-height="600">
      <el-table-column prop="id" label="编号" width="50"></el-table-column>
      <el-table-column prop="code" label="商品编码" width="80"></el-table-column>
      <el-table-column prop="name" label="商品名称" width="400"></el-table-column>
      <el-table-column prop="model" label="型号" width="100"></el-table-column>
      <el-table-column prop="bname" label="类别" width="100"></el-table-column>
      <el-table-column prop="unit" label="单位" width="50"></el-table-column>
      <el-table-column prop="purchasingPrice" label="采购价格" width="80"></el-table-column>
      <el-table-column prop="sellingPrice" label="出售价格" width="80"></el-table-column>
      <el-table-column prop="minNum" label="库存下限" width="80"></el-table-column>
      <el-table-column prop="producer" label="生产厂商" width="300"></el-table-column>
      <el-table-column fixed="right" label="权限菜单设置" width="300">
        <template slot-scope="scope">
            <el-button size="mini" type="primary" @click="upd(scope.row)">修改</el-button>
            <el-button size="mini" type="danger" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
<el-pagination @current-change="getGoodsList" :current-page="pagination.pageNum" :page-count="pagination.pages"></el-pagination>

<el-button type="primary" icon="el-icon-circle-plus-outline" @click="addFlag = true">添加客户信息</el-button>

<el-dialog title="编辑信息" :visible.sync="updFlag">
  <el-form :model="updBean">
      
    <el-form-item label="商品编码" :label-width="formLabelWidth">
      <el-input v-model="updBean.code" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="商品名称" :label-width="formLabelWidth">
      <el-input v-model="updBean.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="商品型号" :label-width="formLabelWidth">
      <el-input v-model="updBean.model" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="单位" :label-width="formLabelWidth">
      <el-input v-model="updBean.unit" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="采购价" :label-width="formLabelWidth">
      <el-input v-model="updBean.purchasingPrice" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="销售价" :label-width="formLabelWidth">
      <el-input v-model="updBean.sellingPrice" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="库存下限" :label-width="formLabelWidth">
      <el-input v-model="updBean.minNum" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="生产厂商" :label-width="formLabelWidth">
      <el-input v-model="updBean.producer" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="备注" :label-width="formLabelWidth">
      <el-input v-model="updBean.remarks" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="updFlag = false">取 消</el-button>
    <el-button type="primary" @click="updGood">确 定</el-button>
  </div>
</el-dialog>
  <el-dialog title="添加信息" :visible.sync="addFlag">
  <el-form :model="addBean">
      
    <el-form-item label="商品编码" :label-width="formLabelWidth">
      <el-input v-model="addBean.code" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="商品名称" :label-width="formLabelWidth">
      <el-input v-model="addBean.name" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="商品型号" :label-width="formLabelWidth">
      <el-input v-model="addBean.model" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="单位" :label-width="formLabelWidth">
      <el-input v-model="addBean.unit" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="采购价" :label-width="formLabelWidth">
      <el-input v-model="addBean.purchasingPrice" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="销售价" :label-width="formLabelWidth">
      <el-input v-model="addBean.sellingPrice" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="库存下限" :label-width="formLabelWidth">
      <el-input v-model="addBean.minNum" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="生产厂商" :label-width="formLabelWidth">
      <el-input v-model="addBean.producer" autocomplete="off"></el-input>
    </el-form-item>
    <el-form-item label="备注" :label-width="formLabelWidth">
      <el-input v-model="addBean.remarks" autocomplete="off"></el-input>
    </el-form-item>
  </el-form>
  <div slot="footer" class="dialog-footer">
    <el-button @click="addFlag = false">取 消</el-button>
    <el-button type="primary" @click="addGood">确 定</el-button>
  </div>
</el-dialog>
  </div>
</template>


<script>
export default {
  methods: {
    getGoodsList:function(pageNo){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/getGoodsList",
        params: {
          pageNo: pageNo,
          access_token: localStorage.getItem("access_token")
        }
      }).then(function(res) {
        window.console.log(res,"res")
        $this.GoodsList = res.data.obj.list;
        $this.pagination = res.data.obj;
      });
    },
    upd:function(row){

      window.console.log(row)
      this.updBean=row
      this.updFlag=true
      
    },
     getTypeList:function(){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tSaleListGoods/getTypeList",
        params: {
          access_token: localStorage.getItem("access_token"),
        },
      }).then(function(res) {
        window.console.log(res,"res")
        $this.TypeList=res.data.obj
      });
    },
    updGood:function(){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/update?access_token="+localStorage.getItem("access_token"),
        params:this.updBean
      }).then(function(res) {
        window.console.log(res,"res")
        if(res.data.obj>0){
            alert("修改成功")
            $this.updFlag=false
            $this.getGoodsList(1);
        }else{
          alert("error")
          $this.getGoodsList(1);
        }
        
      });
    },
    addGood:function(){
      var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/insert?access_token="+localStorage.getItem("access_token"),
        params:this.addBean
      }).then(function(res) {
        window.console.log(res,"res")
        if(res.data.obj>0){
            alert("添加成功")
            $this.addFlag=false
            $this.getGoodsList(1);
        }else{
          alert("error")
          $this.getGoodsList(1);
        }
        
      });
    },
    del:function(row){
     var $this = this;
      this.axios({
        method: "post",
        url: "http://localhost:9999/biz/tGoods/delete?access_token="+localStorage.getItem("access_token"),
        params:{
          ids:row.id
        }
      }).then(function(res) {
        window.console.log(res,"res")
        if(res.data.obj>0){
            alert("删除成功")
            $this.getGoodsList(1);
        }else{
          alert("error")
          $this.getGoodsList(1);
        }
        
      });
    }
  },
  data() {
    return {
      GoodsList: [],
      TypeList:[],
      pagination:{},
      addFlag: false,
      addBean:{},
      updFlag: false,
      updBean: {},
      formLabelWidth:'120px'
    };
  },
  mounted() {
    this.getGoodsList(1);
    this.getTypeList();
  }
};
</script>
